package org.shop.pro.config.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.shop.pro.entity.Shop;
import org.shop.pro.entity.Shoptype;
import org.shop.pro.service.ShopService;
import org.shop.pro.service.ShoptypeService;
import org.shop.pro.service.shopgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ShopController {
	Map<String, String> map=new HashMap<String, String>();
	@Autowired
	ShopService shopService;
	@Autowired
	ShoptypeService shoptypeService;
	/***
	 * 
	    * @Title: shoplist
	    * @Description: TODO(这里用一句话描述这个方法的作用)
	    * @param @param model
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping("shop_list")
	public String shoplist(Model model){
		List<Shop> shop= shopService.selectAll();
		model.addAttribute("shoplist",shop);
		return "shop_list";
	}
	
	/***
	 * 
	    * @Title: shopinfo
	    * @Description: TODO(这里用一句话描述这个方法的作用)
	    * @param @param id
	    * @param @param model
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping("shop_info")
	public String shopinfo(Integer id,Model model){
		Shop shop = shopService.selectByPrimaryKey(id);
		model.addAttribute(shop);
		return "shop_info";
	}
	@RequestMapping("shop_bianji")
	public String shopbianji(Model model){
		return "shop_bianji";
	}
	
	
	/***
	 * 
	    * @Title: shopadd
	    * @Description: TODO(这里用一句话描述这个方法的作用)
	    * @param @param model
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping("shop_add")
	public String shopadd(Model model){
		List<Shoptype> shoptype= shoptypeService.selectAll();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String date= format.format(new Date());
		model.addAttribute("shoptypelist",shoptype);
		model.addAttribute("date",date);
		return "shop_add";
	}
	/***
	 * 
	    * @Title: shopadds
	    * @Description: TODO(这里用一句话描述这个方法的作用)
	    * @param @param shop
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping("shop_adds")
	public String shopadds(Shop shop,Model model){
		int x =shopService.insert(shop);
		if(x==0){
			return "redirect:shop_add";
		}
		return "shop_list";
		
	}
	/****
	 * 
	    * @Title: shopshenhelist
	    * @Description: TODO(管理员审核商铺列表)
	    * @param @param modle
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping("shop_shenhelist")
	public String shopshenhelist(Model model){
		List<Shop> shop = shopService.selectShenhe();
		model.addAttribute("shenhelist",shop);
		return "shop_shenhelist";
	}
	@RequestMapping("shop_shenheinfo")
	public String shopshenheinfo(Integer id,Model model){ 
		Shop shop=shopService.selectByPrimaryKey(id);
		model.addAttribute("shop",shop);
		return "shop_shenheinfo";
	}
	@RequestMapping("shop_shenheupd")
	@ResponseBody
	public Object shopshenheupd(Model model,String id){
		int x = shopService.shenheupd(Integer.parseInt(id)); 
		if(x!=0){
			map.put("delResult", "true");
		}else {
			map.put("delResult", "false");
	}
	return map;
	}
	@RequestMapping("shop_quxiaozige")
	@ResponseBody
	public Object shopquxiaozige(String id){
		int x = shopService.zigeupd(Integer.parseInt(id)); 
		if(x!=0){
			map.put("delResult", "true");
		}else {
			map.put("delResult", "                                                                                                                                                    false");
	}
		return map;
	}
	@RequestMapping("shop/shop_info")
	public String shopinfos(String uid ,Model model){
		
		return "shop/shop_info";
	}
	

}
